﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace SPN.Layouts.SPN.pages
{
    public partial class Newsletter : LayoutsPageBase
    {
        #region PageEvents
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SPWeb _Web = SPContext.Current.Web;
                hl_Add.NavigateUrl = _Web.Url + "/_layouts/SPN/pages/NewsletterAdd.aspx";
                hl_Cancel.NavigateUrl = _Web.Url + "/_layouts/settings.aspx";
                this.LoadNewsletterItems(_Web);
            }
        }
        #endregion

        #region ControlsEvents
        protected void lib_NewsletterItem_View_Click(object sender, EventArgs e)
        {
            LinkButton _lib_View = (LinkButton)sender;
            Response.Redirect("/_layouts/SPN/pages/NewsletterView.aspx?nid=" + _lib_View.CommandArgument);
        }
        #endregion

        #region Methods
        void LoadNewsletterItems(SPWeb _Web)
        {
            if (Common.Helper.IsListValid(_Web, Common.Helper._Const_NewsletterListName))
            {
                List<Entities.Newsletter> _NewsletterItems = Common.Helper.GetNewsletterItems(_Web);
                rep_NewsletterItems.DataSource = _NewsletterItems;
                rep_NewsletterItems.DataBind();
            }
        }
        #endregion
    }
}
